// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-12

package responses

import (
	"fmt"
	"gitee.com/go-libs/db-xorm/db"
	"server/app/http/models"
	"server/app/kind"
	"time"
)

// ArcadeMemberResponse
// 钓场会员.
type ArcadeMemberResponse struct {
	Id             int64
	ArcadeId       kind.ArcadeId
	UserId         kind.UserId
	AvailableBegin db.Date
	AvailableEnd   db.Date
	AvailableMonth int
	OrderCount     int
	TicketCount    int
	SpendTotal     float64
	ReturnedTotal  float64

	// InService
	// 服务中.
	//
	// 会员服务的截止日期大于当前时间.
	InService bool
}

// With
// 数据绑定.
func (o *ArcadeMemberResponse) With(m *models.ArcadeMember) *ArcadeMemberResponse {
	o.Id = m.Id
	o.ArcadeId = m.ArcadeId
	o.UserId = m.UserId
	o.AvailableBegin = m.AvailableBegin
	o.AvailableEnd = m.AvailableEnd
	o.AvailableMonth = m.AvailableMonth
	o.OrderCount = m.OrderCount
	o.TicketCount = m.TicketCount
	o.SpendTotal = m.SpendTotal
	o.ReturnedTotal = m.ReturnedTotal

	// 服务中.
	if t, err := time.Parse(time.DateTime, fmt.Sprintf(`%s 23:59:59`, m.AvailableEnd)); err == nil {
		if t.Unix() > time.Now().Unix() {
			o.InService = true
		}
	}
	return o
}
